
 <!DOCTYPE HTML>
<html >
<head>
  <meta charset="UTF-8">
  
    <title>springmvc统一异常拦截方式 | Typhoon&#39;s code space</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="typhoon">
    

    
    <meta name="description" content="背景描述web项目开发过程中和前期线上运行环境,总是会或多或少出现各种异常,比较常见的是有些运行异常或者检测异常直接抛给了前端,导致前端页面出现了一大坨的异常堆栈信息。">
<meta name="keywords" content="异常拦截">
<meta property="og:type" content="article">
<meta property="og:title" content="springmvc统一异常拦截方式">
<meta property="og:url" content="http://scorpioaeolus.oschina.io/2017/07/15/springmvc统一异常拦截/index.html">
<meta property="og:site_name" content="Typhoon&#39;s code space">
<meta property="og:description" content="背景描述web项目开发过程中和前期线上运行环境,总是会或多或少出现各种异常,比较常见的是有些运行异常或者检测异常直接抛给了前端,导致前端页面出现了一大坨的异常堆栈信息。">
<meta property="og:updated_time" content="2017-07-15T06:20:30.334Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="springmvc统一异常拦截方式">
<meta name="twitter:description" content="背景描述web项目开发过程中和前期线上运行环境,总是会或多或少出现各种异常,比较常见的是有些运行异常或者检测异常直接抛给了前端,导致前端页面出现了一大坨的异常堆栈信息。">

    
    <link rel="alternative" href="/atom.xml" title="Typhoon&#39;s code space" type="application/atom+xml">
    
    
    <link rel="icon" href="/typhoon/img/java.png">
    
    
    <link rel="apple-touch-icon" href="/typhoon/img/jacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/typhoon/img/jacman.jpg">
    
    <link rel="stylesheet" href="/typhoon/css/style.css">
</head>

  <body>
    <header>
      
<div>
		
			<div id="imglogo">
				<a href="/typhoon/"><img src="/typhoon/img/java.png" alt="Typhoon&#39;s code space" title="Typhoon&#39;s code space"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/typhoon/" title="Typhoon&#39;s code space">Typhoon&#39;s code space</a></h1>
				<h2 class="blog-motto"></h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="Menu">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/typhoon/">主页</a></li>
					
						<li><a href="/typhoon/archives">归档</a></li>
					
						<li><a href="/typhoon/about">关于</a></li>
					
					<li>
 					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="search" id="search" name="q" autocomplete="off" maxlength="20" placeholder="Search" />
						<input type="hidden" name="q" value="site:scorpioaeolus.oschina.io">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/typhoon/2017/07/15/springmvc统一异常拦截/" title="springmvc统一异常拦截方式" itemprop="url">springmvc统一异常拦截方式</a>
  </h1>
  <p class="article-author">By
       
		<a href="/typhoon/about" title="typhoon" target="_blank" itemprop="author">typhoon</a>
		
  <p class="article-time">
    <time datetime="2017-07-15T04:45:00.000Z" itemprop="datePublished"> Published 2017-07-15</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">Contents</strong>
		
			<ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#背景描述"><span class="toc-number">1.</span> <span class="toc-text">背景描述</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#问题分析"><span class="toc-number">2.</span> <span class="toc-text">问题分析</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#解决方案"><span class="toc-number">3.</span> <span class="toc-text">解决方案</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#代码实现"><span class="toc-number">4.</span> <span class="toc-text">代码实现</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#总结"><span class="toc-number">5.</span> <span class="toc-text">总结</span></a></li></ol>
		
		</div>
		
		<h4 id="背景描述"><a href="#背景描述" class="headerlink" title="背景描述"></a>背景描述</h4><pre><code>web项目开发过程中和前期线上运行环境,总是会或多或少出现各种异常,比较常见的是有些运行异常或者检测异常直接抛给了前端,导致前端页面出现了一大坨的异常堆栈信息。
</code></pre><a id="more"></a>
<pre><code>1.但是站在产品和用户的角度,不管你服务器端出现什么异常,或者说崩溃的东西,和我没关系；
2.站在B/S交互的角度,你Server端的运行错误与否和我Browser端没太大关联,我任何一个操作,
  只有成功和失败两种结果,不存在一直加载中,同时我也不想看到一大堆密密麻麻看不懂的东西。

3.客户端希望看到的,是服务器端处理成功或者失败对应响应码和数据,或者处理异常被捕获后返回的提前约定的错误码和错误信息
</code></pre><h4 id="问题分析"><a href="#问题分析" class="headerlink" title="问题分析"></a>问题分析</h4><pre><code>   对于上述问题,我们有很多处理和解决方案,比如:

1.在业务编码层面(主要针对service和dao层),做足够的参数检验和逻辑判断,
降低由于编码不严谨或者逻辑分析不到位,导致的逻辑异常


2.在服务调用层面或者说和前端直接打交道层(主要针对controller层),对基础的请求参数做合法性校验和鉴权,
对下层服务调用用try...catch包装,可以解决下层业务层面的检测异常和运行异常,同时也可以捕获框架层面的调用异常,
例如使用rpc框架dubbo,我们可能会出现服务调用超时异常,参数过大异常(传输参数超过dubbo默认大小或者自定义配置大小),
请求和响应序列化异常等等,如果我们不做处理,这些异常直接就把堆栈信息抛给前端了
</code></pre><h4 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h4><pre><code>    对于预知和不可预知的异常,从用户使用,到前端渲染,到服务器业务处理以及最底层数据库查询和持久化分析,我们可以得出很多互补的解决方案:

  1.服务层(逻辑处理层service和dao)对逻辑做详尽的分析,对参数做可靠地校验,         
  对处理结果做好封装,对捕获的异常仔细斟酌要不要向调用方抛出.

  2.调用层(参数解析和鉴权层controller)对前端请求参数做严谨的合法性校验(非         
  空,格式)以及参数鉴权,对调用服务用try...catch做异常捕获,对捕获的异常做         
  处理,返回给前端错误码和错误信息

  3.交互层(和用户直接打交道的前端页面)对响应信息做容错处理,对服务器返回的         
  错误码和错误信息包装转换后变成用户可以理解的信息展示出来.前端对服务请         
  求也做超时容错处理,并考虑做错误上报处理.


    前边的处理方式,貌似是比较严谨的,但是还有一点需要注意,就是从上述的2到3的过程中也可能出现异常,
也就是如果controller层处理不当,那么久把产生的异常直接抛给了前端,这肯定是一种不合理的做法.
那么我们就要考虑的springmvc框架层面对控制器返回给前端的结果做统一异常处理,这样的活我们的
异常处理 链,通过1和2以及下边的4步骤,一环扣一环,做到所有的异常都在服务器端处理掉,
统一异常处理描述如下:

  4.框架层统一异常处理机制,对控制器层所有的漏网之鱼做拦截处理,然后跳转到         
  对应的错误页面,或者如果是前后端分离的话,可以处理后返回给前端相应的错误码.
</code></pre><h4 id="代码实现"><a href="#代码实现" class="headerlink" title="代码实现"></a>代码实现</h4><pre><code>   目前springmvc框架统一异常处理方案大概有三种,下面将一一介绍其使用方式:


1.使用@ExceptionHandler进行处理
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">@ExceptionHandler(Exception.class)</div><div class="line">public String getPage() &#123;</div><div class="line">	return &quot;/index&quot;;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>直接在controller层具体的防范上加上@ExceptionHandler注解,就可以对该方法可能抛出的异常做处理,参考@ExceptionHandler源码:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">@Target(ElementType.METHOD)</div><div class="line">@Retention(RetentionPolicy.RUNTIME)</div><div class="line">@Documented</div><div class="line">public @interface ExceptionHandler &#123;</div><div class="line"></div><div class="line">/**</div><div class="line"> * Exceptions handled by the annotation method. If empty, will default</div><div class="line"> * to any exceptions listed in the method argument list.</div><div class="line"> */</div><div class="line">Class&lt;? extends Throwable&gt;[] value() default &#123;&#125;;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>   发现此注解可以传一个参数,也就是具体的要拦截的异常类型
 优点:1.灵活,可以配置到具体的方法层面 2.简单,不需要再做多余的配置
 缺点:在一个很庞大的网站或者系统中,每个方法上边都要加注解,并且容易溜掉



2.使用SimpleMappingExceptionResolver实现异常处理 



   在springmvc主配置文件中添加一下内容:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">&lt;bean class=&quot;org.springframework.web.servlet.handler.SimpleMappingExceptionResolver&quot;&gt;  </div><div class="line">    &lt;!-- 定义默认的异常处理页面，当该异常类型的注册时使用 --&gt;  </div><div class="line">    &lt;property name=&quot;defaultErrorView&quot; value=&quot;error&quot;&gt;&lt;/property&gt;  </div><div class="line">    &lt;!-- 定义异常处理页面用来获取异常信息的变量名，默认名为exception --&gt;  </div><div class="line">    &lt;property name=&quot;exceptionAttribute&quot; value=&quot;ex&quot;&gt;&lt;/property&gt;  </div><div class="line">    &lt;!-- 定义需要特殊处理的异常，用类名或完全路径名作为key，异常也页名作为值 --&gt;  </div><div class="line">    &lt;property name=&quot;exceptionMappings&quot;&gt;  </div><div class="line">        &lt;props&gt;  </div><div class="line">            &lt;prop key=&quot;com.typhoon.spring_shiro.exception.BusinessException&quot;&gt;error-business&lt;/prop&gt;  </div><div class="line">            &lt;prop key=&quot;com.typhoon.spring_shiro.exception.ParameterException&quot;&gt;error-parameter&lt;/prop&gt;  </div><div class="line">  </div><div class="line">            &lt;!-- 这里还可以继续扩展对不同异常类型的处理 --&gt;  </div><div class="line">        &lt;/props&gt;  </div><div class="line">    &lt;/property&gt;  </div><div class="line">&lt;/bean&gt;</div></pre></td></tr></table></figure>
<pre><code>优点:能拦截所有可能出现的异常,可以对自定义异常做特殊处理
缺点:①.需要添加配置 ②.在多人团队开发的多模块业务中,如果有人添加了自定义异常,需要修改配置


3.实现HandlerExceptionResolver接口自定义异常处理器

   我们在web层自定义异常处理器,然后添加到配置中
</code></pre><p>代码实现<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div></pre></td><td class="code"><pre><div class="line">/**</div><div class="line"> * web层统一异常处理类</div><div class="line"> * </div><div class="line"> * @author Typhoon</div><div class="line"> * @date 2017-05-22 18:17</div><div class="line"> * @since V2.0</div><div class="line"> */</div><div class="line">public class WebExceptionResolver implements HandlerExceptionResolver &#123;</div><div class="line">private static final Logger LOGGER = LoggerFactory.getLogger(WebExceptionResolver.class);		</div><div class="line">@Override</div><div class="line">public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) &#123;</div><div class="line">	LOGGER.info(&quot;捕获web层异常&quot;,ex);</div><div class="line">    Map&lt;String, Object&gt; results = new HashMap&lt;String, Object&gt;();</div><div class="line">    results.put(&quot;code&quot;, &quot;999&quot;);</div><div class="line">    results.put(&quot;msg&quot;, &quot;系统异常&quot;);</div><div class="line">    if(ex instanceof UnauthenticatedException || ex instanceof UnauthorizedException) &#123;//授权异常</div><div class="line">        results.put(&quot;code&quot;, &quot;403&quot;);</div><div class="line">        results.put(&quot;msg&quot;, &quot;无权操作&quot;);</div><div class="line">    &#125;</div><div class="line">	ModelAndView mv = new ModelAndView();  </div><div class="line">    /*  使用FastJson提供的FastJsonJsonView视图返回，不需要捕获异常   */  </div><div class="line">    FastJsonJsonView view = new FastJsonJsonView();  </div><div class="line">    view.setAttributesMap(results);</div><div class="line">    mv.setView(view);   </div><div class="line">    return mv;  </div><div class="line">//// 根据不同错误转向不同页面  </div><div class="line">//if(ex instanceof BusinessException) &#123;  </div><div class="line">//return new ModelAndView(&quot;error-business&quot;, model);  </div><div class="line">//&#125;else if(ex instanceof ParameterException) &#123;  </div><div class="line">//return new ModelAndView(&quot;error-parameter&quot;, model);  </div><div class="line">//&#125; else &#123;  </div><div class="line">//return new ModelAndView(&quot;error&quot;, model);  </div><div class="line">//&#125;     </div><div class="line">&#125;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>添加配置<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">&lt;!-- 统一异常捕获 --&gt;</div><div class="line">&lt;bean id=&quot;exceptionResolver&quot; class=&quot;com.typhoon.spring_shiro.controller.resolver.WebExceptionResolver&quot;/&gt;</div></pre></td></tr></table></figure></p>
<pre><code>优点:①可以自定义处理逻辑,根据不同的异常类型跳转到不同的错误页面,也可以在前后端分离的情况下,
根据不同的异常返回给前端不同的错误码和错误信息
缺点:①有增加新的异常需要抛出,可能需要修改拦截处理逻辑(例如:新增了退费逻辑,在退费异常或者
失败情况下前端需要根据响应码做提示或跳转,那么就需要在拦截器层增加退费异常的判断) 
②需要修改spring配置
</code></pre><h4 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h4><pre><code>    不同的场景可以选择不同的异常拦截方式(在某些场景下可以配合使用),但是不能一概而定,不要根据具体的业务区做判定。
但是在zhenaiwang我们的处理方式是选择第三种拦截方式,因为我们做了前后端分离,所有的前端请求都是返回的json,
这个时候自定义异常处理的优势有显现出来,注解和通用配置略显不足.


    **ps**:欢迎各位大神指教和拍砖.如果能给您带来收获,那是我的荣幸!!!
</code></pre>  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">

<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/typhoon/categories/案例分析/">案例分析</a>
</div>


  <div class="article-tags">
  
  <span></span> <a href="/typhoon/tags/异常拦截/">异常拦截</a>
  </div>

</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://scorpioaeolus.oschina.io/2017/07/15/springmvc统一异常拦截/" data-title="springmvc统一异常拦截方式 | Typhoon&#39;s code space" data-tsina="null" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/typhoon/2017/07/17/dubbo过滤器/" title="dubbo自定义过滤器">
  <strong>上一篇：</strong><br/>
  <span>
  dubbo自定义过滤器</span>
</a>
</div>


<div class="next">
<a href="/typhoon/2017/07/12/并发扣减库存方案二/"  title="并发扣减库存方案二">
 <strong>下一篇：</strong><br/> 
 <span>并发扣减库存方案二
</span>
</a>
</div>

</nav>

	


</div>  
      <div class="openaside"><a class="navbutton" href="#" title="Show Sidebar"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">Contents</strong>
 
 <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#背景描述"><span class="toc-number">1.</span> <span class="toc-text">背景描述</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#问题分析"><span class="toc-number">2.</span> <span class="toc-text">问题分析</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#解决方案"><span class="toc-number">3.</span> <span class="toc-text">解决方案</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#代码实现"><span class="toc-number">4.</span> <span class="toc-text">代码实现</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#总结"><span class="toc-number">5.</span> <span class="toc-text">总结</span></a></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="Hide Sidebar"></a></div>
<aside class="clearfix">

  


  
<div class="categorieslist">
	<p class="asidetitle">Categories</p>
		<ul>
		
		  
			<li><a href="/typhoon/categories/dubbo/" title="dubbo">dubbo<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java性能优化/" title="java性能优化">java性能优化<sup>17</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java源码分析/" title="java源码分析">java源码分析<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/motan/" title="motan">motan<sup>2</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/spring/" title="spring">spring<sup>11</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springboot/" title="springboot">springboot<sup>28</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springmvc/" title="springmvc">springmvc<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/容器/" title="容器">容器<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/工具/" title="工具">工具<sup>7</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/性能优化/" title="性能优化">性能优化<sup>5</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/架构/" title="架构">架构<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/案例分析/" title="案例分析">案例分析<sup>13</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/缓存/" title="缓存">缓存<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/面试题/" title="面试题">面试题<sup>1</sup></a></li>
		  
		
		</ul>
</div>


  
<div class="tagslist">
	<p class="asidetitle">Tags</p>
		<ul class="clearfix">
		
			
				<li><a href="/typhoon/tags/springboot/" title="springboot">springboot<sup>28</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/java性能优化/" title="java性能优化">java性能优化<sup>9</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/限流/" title="限流">限流<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring5/" title="Spring5">Spring5<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/案例分析/" title="案例分析">案例分析<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/性能优化/" title="性能优化">性能优化<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring/" title="Spring">Spring<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo/" title="dubbo">dubbo<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/分页/" title="分页">分页<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/并发/" title="并发">并发<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/异常拦截/" title="异常拦截">异常拦截<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo分布式事务/" title="dubbo分布式事务">dubbo分布式事务<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/自带图片/" title="自带图片">自带图片<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/svn导出mvn项目/" title="svn导出mvn项目">svn导出mvn项目<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo过滤器/" title="dubbo过滤器">dubbo过滤器<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/排序性能对比/" title="排序性能对比">排序性能对比<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/ListenableFuture/" title="ListenableFuture">ListenableFuture<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/PropertyChangeListener/" title="PropertyChangeListener">PropertyChangeListener<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/jdbcTemplate高可用/" title="jdbcTemplate高可用">jdbcTemplate高可用<sup>1</sup></a></li>
			
		
		</ul>
</div>


  <div class="linkslist">
  <p class="asidetitle">Links</p>
    <ul>
        
          <li>
            
            	<a href="https://coderq.com" target="_blank" title="一个面向程序员交流分享的新一代社区">码农圈</a>
            
          </li>
        
          <li>
            
            	<a href="http://wuchong.me" target="_blank" title="Jark&#39;s Blog">Jark&#39;s Blog</a>
            
          </li>
        
    </ul>
</div>

  


  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS</a>
</div>

  <div class="weiboshow">
  <p class="asidetitle">Weibo</p>
    <iframe width="100%" height="119" class="share_self"  frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=119&fansRow=2&ptype=1&speed=0&skin=9&isTitle=1&noborder=1&isWeibo=0&isFans=0&uid=null&verifier=b3593ceb&dpc=1"></iframe>
</div>


</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> Hello ,I&#39;m a java coder. <br/>
			This is my blog,believe it or not.</p>
	</section>
	 
	<div class="social-font" class="clearfix">
		
		
		
		
		
		
		
		
		
		
		<a href="mailto:ScorpioAeolus@163.com" target="_blank" class="icon-email" title="Email Me"></a>
		
	</div>
			
		

		<p class="copyright">
		Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/wuchong/jacman" target="_blank" title="Jacman">Jacman</a> © 2019 
		
		<a href="/typhoon/about" target="_blank" title="typhoon">typhoon</a>
		
		
		</p>
</div>
</footer>
    <script src="/typhoon/js/jquery-2.0.3.min.js"></script>
<script src="/typhoon/js/jquery.imagesloaded.min.js"></script>
<script src="/typhoon/js/gallery.js"></script>
<script src="/typhoon/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>









<link rel="stylesheet" href="/typhoon/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/typhoon/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->



<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?e6d1f421bbc9962127a50488f9ed37d1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>



<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="Back to Top"><img src="/typhoon/img/scrollup.png"/></a>
	</div>
	<script src="/typhoon/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
